package com.gs.seckill.job;

import com.gs.common.core.redis.RedisCache;
import com.gs.gaosheng.domain.GsGoods;
import com.gs.seckill.mapper.SecKillMapper;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;

import javax.annotation.Resource;
import java.util.List;

public class SecKillHot extends QuartzJobBean {

  @Resource
  private SecKillMapper secKillMapper;

  @Resource
  private RedisCache redisCache;

  @Override
  protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
    List<GsGoods> goods = redisCache.getCacheList("seckill");
    for (GsGoods good : goods) {
      secKillMapper.updateStatus(good.getGoodsId());
    }
  }
}
